﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Lilium.LParse
{
    [Obsolete("This ParserState implementation this is for testing purposes only.")]
    public class TextReaderParserState : ParserState<char>
    {
        public TextReaderParserState(TextReader textReader)
        {
            if (textReader == null) throw new ArgumentNullException("textReader");

            m_TextReader = textReader;

            var chr = TextReader.Read();
            if (chr != -1)
                Current = (char)chr;
            else
                Eof = true;
        }

        public override long CreateBookmark()
        {
            throw new NotImplementedException();
        }

        public override void CancelBookmark(long bookmark)
        {
            throw new NotImplementedException();
        }

        public override long CurrentBookmark()
        {
            throw new NotImplementedException();
        }

        public override void Next()
        {
            if (!Eof)
            {
                Position++;
                DiscardErrors();
                var chr = TextReader.Read();
                if (chr != -1)
                    Current = (char)chr;
                else
                    Eof = true;
            }
        }

        public override void RestoreBookmark(long bookmark)
        {
            throw new NotImplementedException();
        }

        #region public long Position

        private long m_Position;

        public long Position
        {
            get { return m_Position; }
            private set { m_Position = value; }
        }

        #endregion

        protected override string ShowPosition()
        {
            return Position.ToString();
        }

        #region private TextReader TextReader

        private readonly TextReader m_TextReader;

        private TextReader TextReader
        {
            get
            {
                return m_TextReader;
            }
        }

        #endregion
    }
}